package com.tianqu.tms.www.car.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.entity.Attn;
import com.tianqu.tms.entity.Member;

import net.sf.json.JSONArray;
//20160405
public class IntegralSearchAjaxAction  extends TmsAjaxAction{
	private Logger logger = Logger.getLogger(IntegralSearchAjaxAction.class);
	@Override
	public void process( ActionMapping mapping, ActionForm form
	                                          , HttpServletRequest request
	                                          , HttpServletResponse response
	                                          , UserContext uc)throws TmsException {
		logger.debug(this.getClass().getName() + "#execute.");
		
		String accessCardNo = request.getParameter("accessCardNo");
		//
		Member member = new Member();
		member = member.getIntegralManagementInfo(accessCardNo);
        //
		Attn attn = new Attn();
		attn = attn.getIntegralInfo(accessCardNo);
		
		int customerType = 2;//member:2 attn:3
		String customerName = "";
		String photoUrl = "";
		String integralStatus = "4"; //1：正常 2：删除 3：禁用 ,4不存在
		String customerId = "";
		HashMap map = new HashMap();
		if(member!=null){
			customerType = 2;
			customerName = member.getRealName();
			integralStatus = member.getUserId();
			customerId = member.getMemId() +"";
		}else if(attn!=null){
			customerType = 3;
			customerName = attn.getAttnName();
			photoUrl = attn.getAttnPhoto();
			integralStatus = attn.getUserId();
			customerId = attn.getAttnId();
		}
		
		map.put("customerId", customerId);
		map.put("customerType", customerType);
		map.put("customerName", customerName);
		map.put("integralStatus",integralStatus);
		map.put("photoUrl", photoUrl);
		responseValues(response, JSONArray.fromObject(map).toString(), TEXT);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}
}
